<div id="basket"><?php
 //echo session_encode();
	// dumps info about a session 
	//echo session_encode();
	if(!isset($boOmitDetails))
		$boOmitDetails = null;
	if(!isset($boOmitBasket))
		$boOmitBasket = null;
	$boBasketEmpty = null;	
		 
  	$intItemNumber = 0;
  	$intCartSubTotal = 0;
	$intCatTotal = 0;	
	$intCartWeightTotal = 0;  
	$strHTML= null;
	if(session_encode()){
	   $session_array = explode(";",session_encode());
	}
		for ($x = 0; $x < count($session_array); $x++) { 
			if (substr($session_array[$x],0,7)=="sesItem")
			{
				//echo "session array ".$session_array[$x]."<br>";
				// look up eregi in PHP book to explain the following
				// find 'sesItem' and write to $arrMatch[1]
				// find numbers and write to $arrMatch[2] (productID)
				// find '|i:' and write to $arrMatch[7]
				// find numbers and write to $arrMatch[8] (quantity)

				//sesItem1_1_5|i:4
				if (eregi("(sesItem)([0-9]{1,9})(\_)([0-9]{1,9})(\_)([0-9]{1,9})(\|i\:)([0-9]{1,9})$",$session_array[$x], $arrMatch)){	
					
					/*	
						$strHTML .= "0 - $arrMatch[0] \n<br>"; 
						$strHTML .= "1 - $arrMatch[1] \n<br>"; 
						$strHTML .= "2 -Product ID $arrMatch[2] \n<br>";
						$strHTML .= "3 - $arrMatch[3] \n<br>";  
						$strHTML .= "4 -Colour  $arrMatch[4] \n<br>";  
						$strHTML .= "5 - $arrMatch[5] \n<br>";  
						$strHTML .= "6 -Size  $arrMatch[6] \n<br>"; 
						$strHTML .= "7 - $arrMatch[7] \n<br>";  
						$strHTML .= "8 -Quantity  $arrMatch[8] \n<br>";
					//*/
								 

					$strBasketItemProductSQL = "SELECT * FROM tblProduct WHERE tblProduct.ID =  '$arrMatch[2]'";
					$objBasketItemProduct = new MySqlResults($strBasketItemProductSQL);	

						if($objBasketItemProduct->ErrorMessages){
							array_push($ActionResults, $objBasketItemProduct->ErrorMessages);
						}

						//echo $strBasketItemProductSQL."<br>";
					
					$intCartSubTotal = $objBasketItemProduct->myrow["UnitPrice"] * $arrMatch[8];
					$intCartWeightTotal = $objBasketItemProduct->myrow['Weight'] + $intCartWeightTotal;	
					//echo $intCartWeightTotal."<br>";
					$intCatTotal = $intCatTotal + $intCartSubTotal;
						
			         	if($boOmitDetails){
			              $intItemNumber += $arrMatch[8];// count number of items in cart
			              $strHTML = "<div align='right' id='basketSummary'>Items : ".$intItemNumber."</div>";
			        	}else{
							$strHTML .= "<div id='basketItemSeperator'><hr/></div>
							<div id='basketItem'>";
							
								$strHTML .= $objBasketItemProduct->myrow["Product"];
								
			        			if($objBasketItemProduct->myrow["QuantityPerUnit"]>1){
									$strHTML .= "&nbsp;(".$objBasketItemProduct->myrow["QuantityPerUnit"]."&nbsp;pack)";
								}
								
								if($arrMatch[4] > 0){
									$strHTML .= " Colour: ".DisplayLookupValue("tblColour","Colour",$arrMatch[4]);
								}
								
								if($arrMatch[6] > 0){
									$strHTML .= " Size: ".DisplayLookupValue("tblSize","Size",$arrMatch[6]);
								}
							
							
							$strHTML .= "</div>\n"; 
							$strHTML .=  "<div id='basketItemPrice' align='right'>qty $arrMatch[8] x&nbsp;".CURRENCY.$objBasketItemProduct->myrow["UnitPrice"]." = ".CURRENCY. number_format($arrMatch[8] * $objBasketItemProduct->myrow["UnitPrice"], 2, '.', '')."</div>";		
			      		}
				}
			}
		}
	
	
	//set order total for carriage charge processing
		$_SESSION['sesOrderTotal'] = $intCatTotal;
		//session_register(sesOrderTotal);

		if ($strHTML == null) {
			// If No Items in basket
			$strHTML = "<div align='right'>Empty&nbsp;</div>";
			$boBasketEmpty = TRUE;
		}else{
			if((DELIVERY_INCLUDED) && ($_SESSION['sesOrderTotal'] >= MIN_ORDER_VALUE )){
				//change from a constant to a session variable so the value can be changed on dislaying the basket
				$intCARRIAGE = "0.00";
			}else{
				$intCARRIAGE = MINIMUM_CARRIAGE;
	
			}		   
					
			//If carriage > 0	
			/*
			if 	($intCartWeightTotal > 0) {
				$strHTML .= "<div align='right'><br>".$intCartWeightTotal."kg</div>";
			}
			*/
	
		    if($boOmitDetails){   	
		    }else{
				$strHTML .= "<hr/>
				<div id='basketSubTotal' align='right'>Sub Total&nbsp;:&nbsp;".CURRENCY.number_format($intCatTotal, 2, '.', '')."</div>";
					if($intCARRIAGE > 0){
						$strHTML .= "<div id='basketCarriage' align='right'><br/>Carriage&nbsp;:&nbsp;".CURRENCY.number_format($intCARRIAGE, 2, '.', '')."</div>";
					}else{
						$strHTML .= "<div id='basketCarriage' align='right'><br/>Carriage : Included</div>";
					}
			}

			$strHTML .= "
			<div id='basketTotal' align='right'>
			<br/>Total&nbsp;:&nbsp;".CURRENCY.number_format($intCatTotal + $intCARRIAGE, 2, '.', '')."</div>";

				if($boOmitDetails){
				}else{
					$strHTML .= "
					<div id='basketMessage' align='right'><br/>".BASKET_MESSAGE."</div>
					<br/>";
				}
				
				if($boOmitBasket){
				}else{
					echo $strHTML; 
				}
			unset($strHTML);
		}?>
</div>
